tt = 1:10

script.file='/homes/31/jc165798/tmp/new4.r'

for (ii in tt) {
	##create the sh file
	zz = file(paste('jobrun_',ii,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat("R CMD BATCH '--args K=",ii,"' ",script.file,' jobrun_',ii,'.Rout --no-save \n',sep='',file=zz)
		cat('##################################\n',file=zz)
	close(zz)
			
	#submit the job
	system(paste('qsub -m n -l nodes=1:ppn=2 jobrun_',ii,'.sh',sep=''))
}
